package fun.codedesign.yinxue.code.engine.jdt;

import org.eclipse.jdt.core.dom.*;

public class AstChangeVisitor extends ASTVisitor {

    @Override
    public boolean visit(TypeDeclaration node) {
        AST ast = node.getAST();

        // 修改AST，添加新的方法
        MethodDeclaration method = ast.newMethodDeclaration();
        method.setName(ast.newSimpleName("hello"));
        node.bodyDeclarations().add(method);

        Block block = ast.newBlock();

        SingleVariableDeclaration singleVariableDeclaration = ast.newSingleVariableDeclaration();
//                singleVariableDeclaration.setName(ast.newSimpleName("Map<String,String> map"));

//                VariableDeclarationFragment variableDeclarationFragment = ast.newVariableDeclarationFragment()

        Assignment assignment =  ast.newAssignment();

//                VariableDeclarationExpression variableDeclarationExpression = ast.newVariableDeclarationExpression()

        assignment.setLeftHandSide(ast.newSimpleName("a"));
        assignment.setOperator(Assignment.Operator.ASSIGN);
        assignment.setRightHandSide(ast.newArrayCreation());

        block.statements().add(ast.newExpressionStatement(assignment));


        method.setBody(block);
        return super.visit(node);
    }

}
